package demo06;


import java.lang.reflect.Field;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/10/27 16:38
 */
public class Test {
    public static void main(String[] args) throws Exception{
        Class<Mouse> mouseClass = Mouse.class;
        Field price = mouseClass.getDeclaredField("price");
        //允许访问私有属性
        price.setAccessible(true);
        //给Mouse创建对象
        Mouse mouse = mouseClass.newInstance();
        System.out.println(mouse);
        //给指定对象赋值
        price.set(mouse,20.00);
        System.out.println(mouse);
        //获取指定对象的值
        Object o = price.get(mouse);
        System.out.println(o);
    }


}
class Computer{
    public int age;
    private String kind;
}

class Mouse extends Computer {
    private double price;
    public int size;

    public void use(){
        System.out.println("这是use方法");
    }

    @Override
    public String toString() {
        return "Mouse{" +
                "age=" + age +
                ", price=" + price +
                ", size=" + size +
                '}';
    }
}

